<template>
  <div class="w-full min-h-[100vh] bg-[#FCFCFC] p-[20px]">
    <div>
      <van-list
        v-model:loading="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="load"
      >
        <div class="bg-white rounded-[10px] w-full p-[10px]">
          <item :list="list"></item>
        </div>
      </van-list>
    </div>
  </div>
</template>
<script setup lang="ts">
import item from "./item.vue";
import { indexGetNotice } from "@/utils/api";
import { ref, reactive } from "vue";
const list = ref([] as any);
const finished = ref(false);
const Info = reactive<infoType>({
  current_page: "",
  last_page: "",
  per_page: "",
  total: "",
});
const page = ref(1);
const loading = ref(false);
const getData = async () => {
  const res = await indexGetNotice({ page: page.value });
  // console.log(res);
  let Infokey: keyof infoType;
  for (Infokey in Info) {
    Info[Infokey] = res.msg[Infokey];
  }
  list.value.push(...res.msg.data);
  if (res.code == 1) {
    loading.value = false;

    if (Info.current_page >= Info.last_page) {
      finished.value = true;
    }
  }
};

const load = () => {
  getData();
  page.value++;
};
</script>
